home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / programming / basic / blitzandpieces / wbpaint.asc < prev   
Encoding:
Text File  |  1999-05-14  |  2.6 KB  |  111 lines

  1. ; James L Boyd's cool WBPaint program :)
  2.  
  3. ; for gadget creation :
  4.  
  5. ; To do :
  6.  
  7. ; Replace WB clearing window at end with appicon, which
  8. ; clears the screen in a much nicer way ;)
  9.  
  10. ; hmm...palette...?
  11.  
  12. Function.w PixelLen{a$}
  13.   rp.l=RastPort(0) ; The rastport of the used window.
  14.   Function Return TextLength_(rp,&a$,Len(a$))
  15. End Function
  16.  
  17. WBStartup ; run from icon
  18.  
  19. FindScreen 0,"Workbench Screen" ; find the WB screen
  20.  
  21. NoCli
  22.  
  23. *scr.Screen=Peek.l(Addr Screen(0))
  24.  
  25. If *scr=0 Then Request "WBPaint","Screen structure failure...","END"
  26.  
  27. ScreenToFront_ *scr
  28.  
  29. *scfont.TextAttr=*scr.Screen\Font           ; font of the screen
  30. fh.b=*scfont.TextAttr\ta_YSize              ; font height
  31. fname$=Peek$(*scfont.TextAttr\ta_Name)      ; font name
  32.  
  33. If fh
  34.   LoadFont 0,fname$,fh
  35. Else Request "WBPaint","Font structure failure...","END"
  36. EndIf
  37.  
  38. th.b=*scr\WBorTop+fh+1 ; title bar height
  39.  
  40. *rp.RastPort=*scr\_RastPort ; the screen's rastport
  41.  
  42. If *rp=0 Then Request "WBPaint","RastPort structure failure...","END"
  43.  
  44. Window 0,0,0,1,1,$1006,"WBPaint",1,2 ; our "hidden" window ;)
  45.  
  46. ;-------------------------------------------
  47.  
  48. ; heh heh heh :
  49.  
  50. ; if you want to add more gadgets, just add the name of the
  51. ; gadget to the DATA ist at the bottom, before the "END" string.
  52. ; they're numbered automatically...
  53.  
  54. .SetUpGadgets
  55.  
  56.   gad.b=50 ; starting gadget
  57.  
  58. While a$<>"END"
  59.   b$=""
  60.   Read a$:b$+" "+a$+" " ; padding spaces
  61.   If a$="END" Then Pop While:Goto skip ; reached end, don't create
  62.   newlen.w=PixelLen{b$} ; gadget width
  63.   GTButton 0,gad,newx.w,0,newlen,th,a$,$10
  64.   newx+PixelLen{b$} ; next gadget's x position
  65.   gad+1 ; increase gadget number
  66. Wend
  67.  
  68. skip ; go here after reading "END"
  69.  
  70. ; widen our window :
  71.  
  72. SizeWindow_ Peek.l(Addr Window(0)),*scr\WBorLeft+*scr\WBorRight+newx-1,fh*3-1
  73.  
  74. ;-------------------------------------------
  75.  
  76. AttachGTList 0,0 ; attach the gadgets
  77.  
  78. loop ; main loop
  79.  
  80. e.l=Event ; grab event
  81.  
  82. VWait ; avoid jerkiness ;)
  83.  
  84. If Joyb(0)=3 ; both mouse buttons
  85.   Move_ *rp,*scr\_MouseX,*scr\_MouseY ; move to x,y
  86.   Draw_ *rp,*scr\_MouseX,*scr\_MouseY ; draw to same position
  87. EndIf
  88.  
  89. Select e ; what was event?
  90.  
  91.   Case $40 ; gadget hit
  92.     Select GadgetHit
  93.       Case 50
  94.         If Request ("WBPaint","Do you really want to quit?!","Yes|No")
  95.           Request "WBPaint","Hacky WB-clearing window coming up!","OK"
  96.           Window 1,0,0,*scr\Width,*scr\Height,0,"",0,0
  97.           End
  98.         EndIf
  99.       Case 51
  100.         Request "WBPaint","WBPaint v0.1 beta||James L Boyd 1999","X"
  101.       Case 52
  102.         Request "WBPaint","WBPaint v0.1 beta||Help requester||Hold left and right buttons, move pointer.","Duh"
  103.     End Select
  104.  
  105. End Select
  106.  
  107. Goto loop
  108.  
  109. strings:
  110. Data$ "Quit","About","Help","END"
  111.